const Koa = require('koa')
const KoaBody = require('koa-body')
const userRouter = require('../router/user.route')
const clientRouter = require('../router/client.route')
const manageRouter = require('../router/manage.route')
const analyseRouter = require('../router/analyse.route')
const errHandler = require('./errHandler')
const path = require('path')
const koaStatic = require('koa-static')
const cors = require('koa2-cors');
const app = new Koa()
// 必须是一个函数

app.use(cors());
app.use(koaStatic(path.join(__dirname, 'public')))

// 在注册路由前注册
app.use(KoaBody({
    multipart: true,
    uploadDir: path.join(__dirname, 'uploads'),
    maxFileSize: 200 * 1024 * 1024,    // 设置上传文件大小最大限制，默认2M
    // 保留文件扩展名
    // keepExtensions: true,

}))


app.use(clientRouter.routes())
app.use(userRouter.routes())
app.use(manageRouter.routes())
app.use(analyseRouter.routes())
app.on('error', errHandler)
module.exports = app